package com.pactera.madp.daemon.quartz.task;

import com.pactera.madp.common.core.constant.SecurityConstants;
import com.pactera.madp.cp.api.feign.RemoteTaskPubService;
import com.pactera.madp.daemon.quartz.constant.enums.MadpQuartzEnum;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.stereotype.Component;


/**
 * @File name：com.pactera.madp.daemon.quartz.task.TaskPubTask
 * @Create on：2022/5/12
 * @Author：tianq
 */
@Component("taskPubTask")
@AllArgsConstructor
public class TaskPubTask {


    private  RemoteTaskPubService remoteTaskPubService;

    /**
     * 开始/结束任务
     * @return
     */
    @SneakyThrows
    public String startTask(){
        remoteTaskPubService.startTask(SecurityConstants.FROM_IN);
        return MadpQuartzEnum.JOB_LOG_STATUS_SUCCESS.getType();
    }

    /**
     * 统计完成情况
     * @return
     */
    @SneakyThrows
    public String taskCompletionStatistics(){
        remoteTaskPubService.taskCompletionStatistics(SecurityConstants.FROM_IN);
        return MadpQuartzEnum.JOB_LOG_STATUS_SUCCESS.getType();
    }


    /**
     * 删除过期30天的任务
     * @return
     */
    @SneakyThrows
    public String deleteOverdueTasks(){
        remoteTaskPubService.deleteOverdueTasks(SecurityConstants.FROM_IN);
        return MadpQuartzEnum.JOB_LOG_STATUS_SUCCESS.getType();
    }

}
